home *** CD-ROM | disk | FTP | other *** search
/ Champak 141 / (Vol 141) Oct 17 2011.iso / Games / Clueless.swf / scripts / Common / ParticleSystem / Effect.as next >
Encoding:
Text File  |  2011-10-17  |  3.6 KB  |  143 lines

  1. package Common.ParticleSystem
  2. {
  3.    import flash.display.MovieClip;
  4.    import flash.display.Sprite;
  5.    
  6.    public class Effect extends Sprite
  7.    {
  8.        
  9.       
  10.       private var active:Boolean = false;
  11.       
  12.       private var disposable:Boolean = true;
  13.       
  14.       private var emitter:Array;
  15.       
  16.       private var parentNode:MovieClip;
  17.       
  18.       public function Effect()
  19.       {
  20.          emitter = new Array();
  21.          active = false;
  22.          disposable = true;
  23.          super();
  24.       }
  25.       
  26.       public static function fromXML(param1:XML) : Effect
  27.       {
  28.          var newEffect:Effect = null;
  29.          var node:XML = null;
  30.          var currentEmitter:Emitter = null;
  31.          var xml:XML = param1;
  32.          newEffect = new Effect();
  33.          try
  34.          {
  35.             for each(node in xml.Emitter)
  36.             {
  37.                currentEmitter = Emitter.fromXML(node);
  38.                newEffect.emitter.push(currentEmitter);
  39.                newEffect.addChild(currentEmitter);
  40.             }
  41.          }
  42.          catch(e:TypeError)
  43.          {
  44.             trace("Could not parse text into XML");
  45.             trace(e.message);
  46.          }
  47.          return newEffect;
  48.       }
  49.       
  50.       public static function clone(param1:Effect) : Effect
  51.       {
  52.          var _loc2_:Effect = null;
  53.          var _loc3_:* = undefined;
  54.          _loc2_ = new Effect();
  55.          _loc3_ = param1.emitter.length;
  56.          while(--_loc3_ != -1)
  57.          {
  58.             _loc2_.emitter[_loc3_] = Emitter.clone(param1.emitter[_loc3_]);
  59.             _loc2_.addChild(_loc2_.emitter[_loc3_]);
  60.          }
  61.          return _loc2_;
  62.       }
  63.       
  64.       public function set Disposable(param1:Boolean) : *
  65.       {
  66.          disposable = param1;
  67.       }
  68.       
  69.       public function startEmission(param1:MovieClip, param2:uint) : void
  70.       {
  71.          var _loc3_:int = 0;
  72.          _loc3_ = 0;
  73.          while(_loc3_ < emitter.length)
  74.          {
  75.             emitter[_loc3_].startEmission();
  76.             _loc3_++;
  77.          }
  78.          active = true;
  79.          parentNode = param1;
  80.          param1.addChild(this);
  81.          mouseEnabled = false;
  82.       }
  83.       
  84.       public function get Active() : Boolean
  85.       {
  86.          return active;
  87.       }
  88.       
  89.       public function setPoint(param1:Number, param2:Number, param3:Boolean = true) : void
  90.       {
  91.          var _loc4_:int = 0;
  92.          _loc4_ = 0;
  93.          while(_loc4_ < emitter.length)
  94.          {
  95.             if(param3)
  96.             {
  97.                emitter[_loc4_].PointA.x = param1;
  98.                emitter[_loc4_].PointA.y = param2;
  99.             }
  100.             else
  101.             {
  102.                emitter[_loc4_].PointB.x = param1;
  103.                emitter[_loc4_].PointB.y = param2;
  104.             }
  105.             _loc4_++;
  106.          }
  107.       }
  108.       
  109.       public function stopEmission() : *
  110.       {
  111.          var _loc1_:int = 0;
  112.          if(parentNode != null && parent == parentNode)
  113.          {
  114.             _loc1_ = 0;
  115.             while(_loc1_ < emitter.length)
  116.             {
  117.                emitter[_loc1_].stopEmission();
  118.                _loc1_++;
  119.             }
  120.             parentNode.removeChild(this);
  121.          }
  122.       }
  123.       
  124.       public function update() : void
  125.       {
  126.          var _loc1_:int = 0;
  127.          if(!active)
  128.          {
  129.             stopEmission();
  130.             return;
  131.          }
  132.          active = false;
  133.          _loc1_ = 0;
  134.          while(_loc1_ < emitter.length)
  135.          {
  136.             emitter[_loc1_].update();
  137.             active = active || Boolean(emitter[_loc1_].Active);
  138.             _loc1_++;
  139.          }
  140.       }
  141.    }
  142. }
  143.